// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   LoginHandler.java

package com.boci.clientapp.authentication.handler;

import com.boci.clientapp.authentication.processor.LoginProcessor;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.handler.AbstractConnectionHandler;
import com.boci.common.handler.StaticConnectionParam;
import com.boci.common.util.Security;
import com.boci.common.vo.ResponseVO;
import java.util.HashMap;

public class LoginHandler extends AbstractConnectionHandler
{

    public String getEncPasswd()
    {
        return strEncPasswd;
    }

    public String getNewEncPasswd()
    {
        return strNewEncPasswd;
    }

    public LoginHandler(String pReqType)
        throws Exception
    {
        super(pReqType);
    }

    public void prepareParameters(HashMap pHashMap)
        throws Exception
    {
        if(ClientAppLoader.enablePKI())
            addEncPasswd(pHashMap);
        super.prepareParameters(pHashMap);
    }

    private void addEncPasswd(HashMap pHashMap)
        throws Exception
    {
        if(getRequestType().equals(RequestTypeConst.BOCI_LOGIN_URL))
        {
            String strPasswd = (String)pHashMap.get("password");
            strEncPasswd = Security.getInstance().encrypt(strPasswd);
            pHashMap.put("encpasswd", strEncPasswd);
            pHashMap.remove("password");
        } else
        if(getRequestType().equals(RequestTypeConst.BOCI_CHG_PWD_URL))
        {
            String strCurPass = (String)pHashMap.get("password");
            String strNewPass = (String)pHashMap.get("newPassword");
            String strConfPass = (String)pHashMap.get("retypePassword");
            strEncPasswd = Security.getInstance().encrypt(strCurPass);
            strNewEncPasswd = Security.getInstance().encrypt(strNewPass);
            String strConfEncPasswd = Security.getInstance().encrypt(strConfPass);
            pHashMap.put("encpasswd", strEncPasswd);
            pHashMap.put("newEncpasswd", strNewEncPasswd);
            pHashMap.put("retypeEncpasswd", strConfEncPasswd);
            pHashMap.remove("password");
            pHashMap.remove("newPassword");
            pHashMap.remove("retypePassword");
        }
    }

    protected ResponseVO processResponse(String pStrResponse)
        throws Exception
    {
        String strErrMsgPrefix = "";
        if(getRequestType().equals(RequestTypeConst.BOCI_LOGIN_URL))
            strErrMsgPrefix = "LOGIN.ERROR_";
        else
        if(getRequestType().equals(RequestTypeConst.BOCI_CHG_PWD_URL))
            strErrMsgPrefix = "CHGPASS.ERROR_";
        LoginProcessor processor = new LoginProcessor(pStrResponse, getRequestType(), strErrMsgPrefix);
        return processor.processXML();
    }

    public ResponseVO login(HashMap pParamMap)
        throws Exception
    {
        if(ClientAppLoader.isServerCertCheckingFlag())
        {
            boolean validServerCert = Security.isValidServerCert(StaticConnectionParam.getInstance().getFullURL(RequestTypeConst.BOCI_URL), ClientAppLoader.getStrCertSubject(), ClientAppLoader.getStrCertIssuer());
            if(!validServerCert)
                throw new Exception("The SSL certificate is not valid.");
        }
        String strResponse = null;
        prepareParameters(pParamMap);
        strResponse = send();
        return processResponse(strResponse);
    }

    public ResponseVO changePassword(HashMap pParams)
        throws Exception
    {
        prepareParameters(pParams);
        String strResponse = "";
        strResponse = send();
        return processResponse(strResponse);
    }

    public ResponseVO logout(HashMap pParams)
        throws Exception
    {
        String strResponse = "";
        strResponse = send();
        return processResponse(strResponse);
    }

    String strEncPasswd;
    String strNewEncPasswd;
}
